package com.itany.corejava.code12_线程;

/**
 * @author Miss Chen
 * @version 1.0
 * @date 2024年07月30日13:36
 */
public class Test05_练习 {
    public static void main(String[] args) {

        //方式一：
        // TicketRunnable tr=new TicketRunnable();
        // Thread t1=new Thread(tr,"线程1");
        // Thread t2=new Thread(tr,"线程2");
        // t1.setPriority(10);
        // t1.start();
        // t2.start();

        TicketThread t1=new TicketThread();
        TicketThread t2=new TicketThread();
        t1.setPriority(10);
        t1.setName("线程1");
        t2.setName("线程2");
        t1.start();
        t2.start();



    }
}
class TicketRunnable implements Runnable{
    //共100张票
    private int num=100;
    @Override
    public void run() {
        while(true){
            if(num==0){
                break;
            }else{
                System.out.println(Thread.currentThread().getName()+"正在出票："+num--);
            }
        }
    }
}

class TicketThread extends Thread{
    static int num=100;

    @Override
    public void run() {
        while(true){
            if(num==0){
                break;
            }else{
                System.out.println(Thread.currentThread().getName()+"正在出票："+num--);
            }
        }
    }
}